*****************************
*** Set Working Directory ***
*****************************


clear all

cd "D:\Dropbox\Research\Corporal Punishment\replication" 
use childdata


gen pvt=1 if TYSCR309==1
replace pvt=0 if pvt==.

gen urban=1 if TYPESITE==1
replace urban=0 if urban==.


tabulate TYPESITE
tabulate TCPHYUR3
tabulate TCPHOTHR3
tabulate CHLDETH
tabulate CHLDREL


drop if ENRSCHR3==0
drop if _merge != 3
drop if TCPHYUR3>2
drop if TCPHOTHR>2
drop if REGION>24
drop if CBRJOBR3>5
drop if CAG3R3>5
drop if DADED==77
drop if MUMED==77
drop if MUMED==88
drop if MUMED==29
drop if CAREED==88
drop if BULLDR3==77
drop if CLUSTID==99
drop if wi==.
drop if urban==. 
drop if math_co==.
drop if egra_co==.
drop if score_ppvt==.
drop if NMEHLTR3==.


gen tchrbeat=1 if WRSTSCR3==1
replace tchrbeat=0 if tchrbeat==.

gen nsycls=1 if WRSTSCR3==14
replace nsycls=0 if nsycls==.

gen stfgt=1 if WRSTSCR3==15
replace stfgt=0 if stfgt==.

gen noprob=1 if WRSTSCR3==30
replace noprob=0 if noprob==.

gen goodsc1=1 if WHSCHR31==5
replace goodsc1=0 if goodsc1==.

gen goodsc2=1 if WHSCHR32==5
replace goodsc2=0 if goodsc2==.

gen goodsc3=1 if WHSCHR33==5
replace goodsc3=0 if goodsc3==.

gen goodsc = 1 if goodsc1==1 | goodsc2==1
replace goodsc=0 if goodsc==. 

gen male=1 if SEX==1
replace male=0 if male==.

replace CAG3R3=-1*CAG3R3

gen agechild2 = agechild^2

gen punished = 1
replace punished = 0 if TCPHYUR3 == 0

gen othrspunshd = 1
replace othrspunshd = 0 if TCPHOTHR3 == 0 

gen pun_nev = 0 
replace pun_nev = 1 if TCPHYUR3 == 0 

gen pun_sel = 0 
replace pun_sel = 1 if TCPHYUR3 == 1 

gen pun_oft = 0 
replace pun_oft = 1 if TCPHYUR3 == 2 

gen oth_nev = 0 
replace oth_nev = 1 if TCPHOTHR3 == 0 

gen oth_sel = 0 
replace oth_sel = 1 if TCPHOTHR3 == 1 

gen oth_oft = 0 
replace oth_oft = 1 if TCPHOTHR3 == 2 


tabulate REGION, generate(regdummy)
tabulate CHLDETH, generate(ethdummy)
tabulate CHLDREL, generate(reldummy)

xi i.CLUSTID

tabulate DADED, gen(fathedu)
tabulate MUMED, gen(mothedu)
tabulate CAREED, gen(careedu)




**************************
*** Summary Statistics ***
**************************

summarize math_co egra_co TCPHYUR3 TCPHOTHR3 tchrbeat agechild NMEHLTR3 bmi score_ppvt goodsc BULLDR3 wi urban male CBRJOBR3

tab TCPHYUR3 

tab TCPHOTHR3 

tab WRSTSCR3 


************************************
************************************

*******************
*** Regressions ***
*******************

***Math***

reg math_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust 

reg math_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust beta 


ivreg2 math_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3) 




***EGRA***

reg egra_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust 

reg egra_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust beta 


ivreg2 egra_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3) 





************************************
************************************



************************************
************************************

**************************
*** Robustness Check-1 ***
**************************

***Math***

reg math_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust

ivreg2 math_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3)



***EGRA***

reg egra_co TCPHYUR3 agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust

ivreg2 egra_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3) 


************************************
************************************





**************************
*** Robustness Check-3 ***
**************************


*** math *** 

reg math_co pun_sel pun_oft agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust 


ivreg2 math_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (pun_sel pun_oft = oth_sel oth_oft), gmm2s first endog(pun_sel pun_oft) 



*** egra *** 


reg egra_co pun_sel pun_oft agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID*, robust 


ivreg2 egra_co agechild NMEHLTR3 bmi score_ppvt pvt goodsc BULLDR3 wi urban male CBRJOBR3 mothedu* regdummy* ethdummy* reldummy* _ICLUSTID* (pun_sel pun_oft = oth_sel oth_oft), gmm2s first endog(pun_sel pun_oft)




************************************
************************************




************************************
************************************

**************************
*** Robustness Check-2 ***
**************************

use childdata_new, clear  
sum 

drop if clustid==. 
replace commid = subinstr(commid, "IN","",.) 
destring commid, replace  
drop if typesite==. 
drop if region==. 
drop if chethnic==. 
drop if chldrel==. 
drop if agemon==. 
drop if bmi==. 
drop if momedu==. 
drop if GENDYLR4==. 
drop if engl_raw==. 
drop if lang_raw==. 
drop if maths_raw==. 
drop if TCPHYUR3>2
drop if TCPHOTHR>2 
drop if ppvt==. 
drop if BULLDR4==. 
drop if NMEHLTR4==. 

sum 

tabulate clustid, gen(clustdummy)  
gen urban=1 if typesite==1
replace urban=0 if urban==.  
tabulate region, gen(regiondummy)  
gen male=1 if GENDYLR4==1
replace male=0 if male==. 
tabulate momedu, gen(momedudummy) 
tabulate chethnic, gen(ethdummy)  
tabulate chldrel, gen(reldummy)  

sum  


**** english ***


reg engl_raw TCPHYUR3 BULLDR4 wi ppvt agemon bmi urban male NMEHLTR4 clustd* regiond* momedud* ethd* reld*, robust  


ivreg2 engl_raw BULLDR4 wi ppvt agemon bmi urban male NMEHLTR4 clustd* regiond* momedud* ethd* reld* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3) 


*** math *** 


reg maths_raw TCPHYUR3 BULLDR4 wi ppvt agemon bmi urban male NMEHLTR4 clustd* regiond* momedud* ethd* reld*, robust  


ivreg2 maths_raw BULLDR4 wi ppvt agemon bmi urban male NMEHLTR4 clustd* regiond* momedud* ethd* reld* (TCPHYUR3 = TCPHOTHR3), gmm2s first endog(TCPHYUR3) 








